home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sun4c / archive / tcltk.z / tcltk / slib / tk / demos / widget < prev   
Text File  |  1994-09-20  |  9KB  |  189 lines

  1. #!///////////////////////////////////////////////////////////////////////////usr/STAGE/bin/wish -f
  2. #
  3. # This script demonstrates the various widgets provided by Tk,
  4. # along with many of the features of the Tk toolkit.  This file
  5. # only contains code to generate the main window for the
  6. # application, which invokes individual demonstrations.  The
  7. # code for the actual demonstrations is contained in separate
  8. # ".tcl" files is this directory, which are auto-loaded by Tcl
  9. # when they are needed.  To find the code for a particular
  10. # demo, look below for the procedure that's invoked by its menu
  11. # entry, then grep for the file that contains the procedure
  12. # definition.
  13.  
  14. set auto_path "$tk_library/demos $auto_path"
  15. wm title . "Widget Demonstration"
  16.  
  17. #-------------------------------------------------------
  18. # The code below create the main window, consisting of a
  19. # menu bar and a message explaining the basic operation
  20. # of the program.
  21. #-------------------------------------------------------
  22.  
  23. frame .menu -relief raised -borderwidth 1
  24. message .msg -font -Adobe-times-medium-r-normal--*-180* -relief raised -width 500 \
  25. -borderwidth 1 -text "This application demonstrates the widgets provided by the Tk toolkit.  The menus above are organized by widget type:  each menu contains one or more demonstrations of a particular type of widget.  To invoke a demonstration, press mouse button 1 over one of the menu buttons above, drag the mouse to the desired entry in the menu, then release the mouse button.
  26.  
  27. To exit this demonstration, invoke the \"Quit\" entry in the \"Misc\" menu."
  28.  
  29. pack .menu -side top -fill x
  30. pack .msg -side bottom -expand yes -fill both
  31.  
  32. #-------------------------------------------------------
  33. # The code below creates all the menus, which invoke procedures
  34. # to create particular demonstrations of various widgets.
  35. #-------------------------------------------------------
  36.  
  37. menubutton .menu.button -text "Labels/Buttons" -menu .menu.button.m \
  38.     -underline 7
  39. menu .menu.button.m
  40. .menu.button.m add command -label "Labels" -command "mkLabel" -underline 0
  41. .menu.button.m add command -label "Buttons" -command "mkButton" -underline 0
  42. .menu.button.m add command -label "Checkbuttons" -command "mkCheck" \
  43.     -underline 0
  44. .menu.button.m add command -label "Radiobuttons" -command "mkRadio" \
  45.     -underline 0
  46. .menu.button.m add command -label "15-puzzle" -command "mkPuzzle" -underline 0
  47. .menu.button.m add command -label "Iconic buttons" -command "mkIcon" \
  48.     -underline 0
  49.  
  50. menubutton .menu.listbox -text "Listboxes" -menu .menu.listbox.m \
  51.     -underline 0
  52. menu .menu.listbox.m
  53. .menu.listbox.m add command -label "States" -command mkListbox -underline 0
  54. .menu.listbox.m add command -label "Colors" -command mkListbox2 -underline 0
  55. .menu.listbox.m add command -label "Well-known sayings" -command mkListbox3 \
  56.     -underline 0
  57.  
  58. menubutton .menu.entry -text "Entries" -menu .menu.entry.m \
  59.     -underline 0
  60. menu .menu.entry.m
  61. .menu.entry.m add command -label "Without scrollbars" -command mkEntry \
  62.     -underline 4
  63. .menu.entry.m add command -label "With scrollbars" -command mkEntry2 \
  64.     -underline 0
  65. .menu.entry.m add command -label "Simple form" -command mkForm \
  66.     -underline 0
  67.  
  68. menubutton .menu.text -text "Text" -menu .menu.text.m -underline 0
  69. menu .menu.text.m
  70. .menu.text.m add command -label "Basic text" -command mkBasic \
  71.     -underline 0
  72. .menu.text.m add command -label "Display styles" -command mkStyles \
  73.     -underline 0
  74. .menu.text.m add command -label "Command bindings" -command mkTextBind \
  75.     -underline 0
  76. .menu.text.m add command -label Search -command mkTextSearch \
  77.     -underline 0
  78.  
  79. menubutton .menu.scroll -text "Scrollbars" -menu .menu.scroll.m \
  80.     -underline 0
  81. menu .menu.scroll.m
  82. .menu.scroll.m add command -label "Vertical" -command mkListbox2 -underline 0
  83. .menu.scroll.m add command -label "Horizontal" -command mkEntry2 -underline 0
  84.  
  85. menubutton .menu.scale -text "Scales" -menu .menu.scale.m -underline 2
  86. menu .menu.scale.m
  87. .menu.scale.m add command -label "Vertical" -command mkVScale -underline 0
  88. .menu.scale.m add command -label "Horizontal" -command mkHScale -underline 0
  89.  
  90. menubutton .menu.canvas -text "Canvases" -menu .menu.canvas.m \
  91.     -underline 0
  92. menu .menu.canvas.m
  93. .menu.canvas.m add command -label "Item types" -command mkItems -underline 0
  94. .menu.canvas.m add command -label "2-D plot" -command mkPlot -underline 0
  95. .menu.canvas.m add command -label "Text" -command mkCanvText -underline 0
  96. .menu.canvas.m add command -label "Arrow shapes" -command mkArrow -underline 0
  97. .menu.canvas.m add command -label "Ruler" -command mkRuler -underline 0
  98. .menu.canvas.m add command -label "Scrollable canvas" -command mkScroll \
  99.     -underline 0
  100. .menu.canvas.m add command -label "Floor plan" -command mkFloor \
  101.     -underline 0
  102.  
  103. menubutton .menu.menu -text "Menus" -menu .menu.menu.m -underline 0
  104. menu .menu.menu.m
  105. .menu.menu.m add command -label "Print hello" -command {puts stdout "Hello"} \
  106.     -accelerator Control+a -underline 6
  107. bind .msg <Control-a> {puts stdout "Hello"}
  108. .menu.menu.m add command -label "Print goodbye" -command {\
  109.     puts stdout "Goodbye"} -accelerator Control+b -underline 6
  110. bind .msg <Control-b> {puts stdout "Goodbye"}
  111. .menu.menu.m add command -label "Light blue background" \
  112.     -command {.msg config -bg "LightBlue1"} -underline 0
  113. .menu.menu.m add command -label "Info on tear-off menus" -command mkTear \
  114.     -underline 0
  115. .menu.menu.m add cascade -label "Check buttons" -menu .menu.menu.m.check \
  116.     -underline 0
  117. .menu.menu.m add cascade -label "Radio buttons" -menu .menu.menu.m.radio \
  118.     -underline 0
  119. .menu.menu.m add command -bitmap @$tk_library/demos/bitmaps/pattern \
  120.     -command {
  121.     mkDialog .pattern {-text {The menu entry you invoked displays a bitmap rather than a text string.  Other than this, it is just like any other menu entry.} -aspect 250} {OK {}}
  122.     }
  123.  
  124. menu .menu.menu.m.check
  125. .menu.menu.m.check add check -label "Oil checked" -variable oil
  126. .menu.menu.m.check add check -label "Transmission checked" -variable trans
  127. .menu.menu.m.check add check -label "Brakes checked" -variable brakes
  128. .menu.menu.m.check add check -label "Lights checked" -variable lights
  129. .menu.menu.m.check add separator
  130. .menu.menu.m.check add command -label "Show current values" \
  131.     -command "showVars .menu.menu.dialog oil trans brakes lights"
  132. .menu.menu.m.check invoke 1
  133. .menu.menu.m.check invoke 3
  134.  
  135. menu .menu.menu.m.radio
  136. .menu.menu.m.radio add radio -label "10 point" -variable pointSize -value 10
  137. .menu.menu.m.radio add radio -label "14 point" -variable pointSize -value 14
  138. .menu.menu.m.radio add radio -label "18 point" -variable pointSize -value 18
  139. .menu.menu.m.radio add radio -label "24 point" -variable pointSize -value 24
  140. .menu.menu.m.radio add radio -label "32 point" -variable pointSize -value 32
  141. .menu.menu.m.radio add sep
  142. .menu.menu.m.radio add radio -label "Roman" -variable style -value roman
  143. .menu.menu.m.radio add radio -label "Bold" -variable style -value bold
  144. .menu.menu.m.radio add radio -label "Italic" -variable style -value italic
  145. .menu.menu.m.radio add sep
  146. .menu.menu.m.radio add command -label "Show current values" -command \
  147.     "showVars .menu.menu.dialog pointSize style"
  148. .menu.menu.m.radio invoke 1
  149. .menu.menu.m.radio invoke 7
  150.  
  151. menubutton .menu.misc -text Misc -menu .menu.misc.m -underline 1
  152. menu .menu.misc.m
  153. .menu.misc.m add command -label "Modal dialog (local grab)" -command {
  154.     mkDialog .modal {-text {This dialog box is a modal one.  It uses Tk's "grab" command to create a "local grab" on the dialog box.  The grab prevents any pointer-related events from getting to any other windows in the application.  If you press the "OK" button below (or hit the Return key) then the dialog box will go away and things will return to normal.} -aspect 250 -justify left} {OK {}}
  155.     dpos .modal
  156.     tkwait visibility .modal
  157.     grab .modal
  158.     tkwait window .modal
  159. } -underline 0
  160. .menu.misc.m add command -label "Modal dialog (global grab)" -command {
  161.     mkDialog .modal {-text {This is another modal dialog box.  However, in this case a "global grab" is used, which locks up the display so you can't talk to any windows in any applications anywhere, except for the dialog.  If you press the "OK" button below (or hit the Return key) then the dialog box will go away and things will return to normal.} -aspect 250 -justify left} {OK {}}
  162.     dpos .modal
  163.     tkwait visibility .modal
  164.     grab -global .modal
  165.     tkwait window .modal
  166. } -underline 0
  167. .menu.misc.m add command -label "Built-in bitmaps" -command mkBitmaps \
  168.     -underline 0
  169. .menu.misc.m add command -label "Quit" -command "destroy ." -underline 0
  170.  
  171. pack .menu.button .menu.listbox .menu.entry .menu.text .menu.scroll \
  172.     .menu.scale .menu.canvas .menu.menu .menu.misc -side left
  173.  
  174. # Set up for keyboard-based menu traversal
  175.  
  176. bind . <Any-FocusIn> {
  177.     if {("%d" == "NotifyVirtual") && ("%m" == "NotifyNormal")} {
  178.     focus .menu
  179.     }
  180. }
  181. tk_menuBar .menu .menu.button .menu.listbox .menu.entry .menu.text \
  182.     .menu.scroll .menu.scale .menu.canvas .menu.menu .menu.misc
  183.  
  184. # Position a dialog box at a reasonable place on the screen.
  185.  
  186. proc dpos w {
  187.     wm geometry $w +300+300
  188. }
  189.